/*
 * @Author: your name
 * @Date: 2021-12-01 19:09:30
 * @LastEditTime: 2021-12-02 14:19:21
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\client\src\mixins\theme.js
 */
//主题色混入
export default {
    data() {
        return {
            dark: null, //初始状态为空
        };
    },
    methods: {
        //改变模式
        modelBrn() {
            //dark取反
            this.dark = !this.dark;
            //重新存储dark
            window.localStorage.setItem("dark", JSON.stringify(this.dark));
            if (this.dark) {
                //暗夜模式
                window.document.documentElement.setAttribute("data-theme", "dark");
            } else {
                //白天模式
                window.document.documentElement.setAttribute("data-theme", "light");
            }
        },
    },
    mounted() {
        //初始判断dark状态
        if (!this.dark) {
            window.document.documentElement.setAttribute("data-theme", "light");
        } else {
            window.document.documentElement.setAttribute("data-theme", "dark");
        }
    },
    created() {
        //本地存储读取状态信息
        const dark = JSON.parse(window.localStorage.getItem("dark"));
        //不空时去存储的状态
        if (dark !== undefined) {
            this.dark = dark;
        } else {
            //默认为白天模式
            window.localStorage.setItem("dark", JSON.stringify(false));
            this.dark = false;
        }
    },
};